#!/bin/bash

GERRIT_REFSPEC='$GERRIT_REFSPEC'
GERRIT_BRANCH='$GERRIT_BRANCH'
BUILD_NUMBER='$BUILD_NUMBER'
GERRIT_NAME=${GERRIT_NAME:-gerrit}

cat <<EOF
<?xml version='1.0' encoding='UTF-8'?>
<maven2-moduleset plugin="maven-plugin@2.14444">
  <actions/>
  <description></description>
  <keepDependencies>false</keepDependencies>
  <properties/>
  <scm class="hudson.plugins.git.GitSCM" plugin="git@3.0.0">
    <configVersion>2</configVersion>
    <userRemoteConfigs>
      <hudson.plugins.git.UserRemoteConfig>
        <name>origin</name>
        <refspec>$GERRIT_REFSPEC</refspec>
        <url>ssh://jenkins@${GERRIT_NAME}:29418/demo</url>
        <credentialsId>jenkins-master</credentialsId>
      </hudson.plugins.git.UserRemoteConfig>
    </userRemoteConfigs>
    <branches>
      <hudson.plugins.git.BranchSpec>
        <name>$GERRIT_BRANCH</name>
      </hudson.plugins.git.BranchSpec>
    </branches>
    <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
    <submoduleCfg class="list"/>
    <extensions>
      <hudson.plugins.git.extensions.impl.BuildChooserSetting>
        <buildChooser class="com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerBuildChooser" plugin="gerrit-trigger@2.22.0">
          <separator>#</separator>
        </buildChooser>
      </hudson.plugins.git.extensions.impl.BuildChooserSetting>
      <hudson.plugins.git.extensions.impl.CleanBeforeCheckout/>
    </extensions>
  </scm>
  <assignedNode>swarm</assignedNode>
  <canRoam>false</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers>
    <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger plugin="gerrit-trigger@2.22.0">
      <spec></spec>
      <gerritProjects>
        <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject>
          <compareType>PLAIN</compareType>
          <pattern>demo</pattern>
          <branches>
            <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
              <compareType>PLAIN</compareType>
              <pattern>master</pattern>
            </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
          </branches>
          <disableStrictForbiddenFileVerification>false</disableStrictForbiddenFileVerification>
        </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject>
      </gerritProjects>
      <skipVote>
        <onSuccessful>false</onSuccessful>
        <onFailed>false</onFailed>
        <onUnstable>false</onUnstable>
        <onNotBuilt>false</onNotBuilt>
      </skipVote>
      <silentMode>false</silentMode>
      <notificationLevel></notificationLevel>
      <silentStartMode>false</silentStartMode>
      <escapeQuotes>true</escapeQuotes>
      <nameAndEmailParameterMode>PLAIN</nameAndEmailParameterMode>
      <dependencyJobsNames></dependencyJobsNames>
      <commitMessageParameterMode>BASE64</commitMessageParameterMode>
      <changeSubjectParameterMode>PLAIN</changeSubjectParameterMode>
      <commentTextParameterMode>PLAIN</commentTextParameterMode>
      <buildStartMessage></buildStartMessage>
      <buildFailureMessage></buildFailureMessage>
      <buildSuccessfulMessage></buildSuccessfulMessage>
      <buildUnstableMessage></buildUnstableMessage>
      <buildNotBuiltMessage></buildNotBuiltMessage>
      <buildUnsuccessfulFilepath></buildUnsuccessfulFilepath>
      <customUrl></customUrl>
      <serverName>Gerrit</serverName>
      <triggerOnEvents>
        <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
          <excludeDrafts>true</excludeDrafts>
          <excludeTrivialRebase>false</excludeTrivialRebase>
          <excludeNoCodeChange>true</excludeNoCodeChange>
        </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
        <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginDraftPublishedEvent/>
      </triggerOnEvents>
      <dynamicTriggerConfiguration>false</dynamicTriggerConfiguration>
      <triggerConfigURL></triggerConfigURL>
      <triggerInformationAction/>
    </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger>
  </triggers>
  <concurrentBuild>true</concurrentBuild>
  <rootPOM>demo/pom.xml</rootPOM>
  <goals>clean install</goals>
  <aggregatorStyleBuild>true</aggregatorStyleBuild>
  <incrementalBuild>false</incrementalBuild>
  <ignoreUpstremChanges>true</ignoreUpstremChanges>
  <ignoreUnsuccessfulUpstreams>false</ignoreUnsuccessfulUpstreams>
  <archivingDisabled>false</archivingDisabled>
  <siteArchivingDisabled>false</siteArchivingDisabled>
  <fingerprintingDisabled>false</fingerprintingDisabled>
  <resolveDependencies>false</resolveDependencies>
  <processPlugins>false</processPlugins>
  <mavenValidationLevel>-1</mavenValidationLevel>
  <runHeadless>false</runHeadless>
  <disableTriggerDownstreamProjects>false</disableTriggerDownstreamProjects>
  <blockTriggerWhenBuilding>true</blockTriggerWhenBuilding>
  <settings class="jenkins.mvn.DefaultSettingsProvider"/>
  <globalSettings class="jenkins.mvn.DefaultGlobalSettingsProvider"/>
  <reporters/>
  <publishers>
    <hudson.tasks.ArtifactArchiver>
      <artifacts>demo/**/target/*.jar</artifacts>
      <allowEmptyArchive>false</allowEmptyArchive>
      <onlyIfSuccessful>true</onlyIfSuccessful>
      <fingerprint>false</fingerprint>
      <defaultExcludes>true</defaultExcludes>
      <caseSensitive>true</caseSensitive>
    </hudson.tasks.ArtifactArchiver>
    <hudson.plugins.parameterizedtrigger.BuildTrigger plugin="parameterized-trigger@2.32">
      <configs>
        <hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
          <configs>
            <hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
              <properties>SNAPSHOT_BUILD_NUMBER=$BUILD_NUMBER</properties>
            </hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
          </configs>
          <projects>demo-docker</projects>
          <condition>SUCCESS</condition>
          <triggerWithNoParameters>false</triggerWithNoParameters>
        </hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
      </configs>
    </hudson.plugins.parameterizedtrigger.BuildTrigger>
  </publishers>
  <buildWrappers/>
  <prebuilders/>
  <postbuilders/>
  <runPostStepsIfResult>
    <name>FAILURE</name>
    <ordinal>2</ordinal>
    <color>RED</color>
    <completeBuild>true</completeBuild>
  </runPostStepsIfResult>
</maven2-moduleset>
EOF
